/*Copyright &copy; 2015-2016 hibabydance.com All rights reserved.*/
package com.kbus.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.kbus.bean.{{entity}};
import com.kbus.dao.{{entity}}Dao;
import com.kbus.service.{{entity}}Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * {{author}}
 * {{time}}
 */
@Service
@Transactional
public class {{entity}}ServiceImpl implements {{entity}}Service {
  
  @Autowired
  private {{entity}}Dao {{entity.toLowerCase()}}Dao;

  @Override
  public int create{{entity}}({{entity}} {{entity.toLowerCase()}}) {
    {{entity.toLowerCase()}}.setCreateTime(new Date());
    {{entity.toLowerCase()}}.setUpdateTime(new Date());
    int result = {{entity.toLowerCase()}}Dao.insert({{entity.toLowerCase()}});
    return result;
  }

  @Override
  public int update{{entity}}({{entity}} {{entity.toLowerCase()}}) {
    int result = {{entity.toLowerCase()}}Dao.update({{entity.toLowerCase()}});
    return result;
  }

  @Override
  public int delete{{entity}}(String id) {
    int result = {{entity.toLowerCase()}}Dao.delete(id);
    return result;
  }

  @Override
  public {{entity}} getById(String id) {
    {{entity}} result = {{entity.toLowerCase()}}Dao.getById(id);
    return result;
  }

  @Override
  public List<{{entity}}> getAll(int pageNum, int pageSize) {
    PageHelper.startPage(pageNum, pageSize);
    List<{{entity}}> result = {{entity.toLowerCase()}}Dao.getAll();
    return result;
  }

  @Override
  public List<{{entity}}> getAll() {
    List<{{entity}}> result = {{entity.toLowerCase()}}Dao.getAll();
    return result;
  }
}
